package com.sl.au.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.sl.au.entity.customerAllocation;
import com.sl.au.repository.ExdeCustomerAllocationRepository;
import com.sl.au.service.ExdeCustomerAllocationService;

@Service("ExdeCustomerAllocationService")
@Transactional
public class ExdeCustomerAllocationServiceImpl implements ExdeCustomerAllocationService{
	@Autowired
	ExdeCustomerAllocationRepository exdeCustomerAllocationRepository;

	@Override
	public ExdeCustomerAllocationRepository exdeCustomerAllocationRepository() {
		return this.exdeCustomerAllocationRepository;
	}

	@Override
	public List<customerAllocation> getUser(int start, int size, String key) {
		Page<customerAllocation> pages = null;
		Pageable pageable = new PageRequest(start / size, size, Sort.Direction.ASC, "name");
		if(key != null && key != ""){
			pages = exdeCustomerAllocationRepository.getUserList(key,pageable);
		}else{
			pages = exdeCustomerAllocationRepository.getUserList(pageable);
		}
		return pages.getContent();
	}

	@Override
	public long getAllUserCount(String key) {
		if(key != null && key != ""){
			return exdeCustomerAllocationRepository.getUserCount(key);
		}else{
			return exdeCustomerAllocationRepository.getUserCount();
		}
	}

}
